package com.jqsoft.launcher.activity.diabetesMellitus;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.ComponentName;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.webkit.JavascriptInterface;
import android.widget.Toast;

import com.jqsoft.launcher.activity.WebViewActivity;
import com.jqsoft.launcher.activity.bean.HBPGuanLi_PersonInfo;
import com.jqsoft.launcher.activity.bean.UserLoginInfo;
import com.jqsoft.launcher.activity.gairui.GluExample;
import com.jqsoft.launcher.activity.gairui.NibpExample;
import com.jqsoft.launcher.common.BphsConstants;
import com.jqsoft.launcher.common.BphsURL;
import com.jqsoft.launcher.util.CommonUtil;
import com.jqsoft.launcher.util.DateTools;
import com.jqsoft.launcher.util.FileService;
import com.jqsoft.launcher.util.Log;
import com.jqsoft.launcher.util.MessageTools;
import com.jqsoft.launcher.util.StringTools;
import com.jqsoft.launcher.util.WebServiceUtils;
import com.jqsoft.launcher.util.XmlUtil;

import org.apache.commons.lang.StringUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class DiabetesMellitusFollowUpActivity extends WebViewActivity implements
View.OnClickListener {

	HBPGuanLi_PersonInfo personInfo;
	UserLoginInfo info = UserLoginInfo.getInstances();
	String jsonstr =null;
	private int updateIndex=-1;
	private String sPersonID1;
	private String sNo1;//档案编号
	private String sname1;//姓名
	private String sCardNo1;//证件号码

	private String ishuixian="0";

	private String xueya="0";
	private String xuetang="0";
	private String xuehongdanbai="0";
	@Override
	protected void initGui() {
		super.initGui();
		webView.loadUrl("file:///android_asset/tnb_followup_record.html");
		webView.addJavascriptInterface(new JSObject(), "contact"); //糖尿病
	}

	@Override
	protected void initAction() {
		setGoBack();
	}

	@Override
	protected void initData() {
		setTitle("糖尿病患者随访服务记录表");
		Intent intent = getIntent();
        Bundle bundle=intent.getExtras();
        if(bundle!=null){
         personInfo= (HBPGuanLi_PersonInfo) bundle.get("DMGuanLi_PersonInfo");
         jsonstr=bundle.getString("Tjdata");
         sPersonID1=bundle.getString("sPersonID");
         sNo1=bundle.getString("sNo");
         sname1=bundle.getString("sname");
         sCardNo1=bundle.getString("sCardNo");
         updateIndex=bundle.getInt("chakan");

//       上次回显
       if(StringTools.isEmpty(jsonstr)){
      	 jsonstr=bundle.getString("shangciData");
      	 if(StringTools.isNotEmpty(jsonstr)){
      	 ishuixian="1";
      	 }
       }
        }
	}

	@Override
	public void onClick(View v) {
	}

	private final class JSObject {
		//初始化页面
		@JavascriptInterface
		public void getHtml() {
			runOnUiThread(new Runnable() {
				@Override
				public void run() {
					try {
						Map<String, String> map = new HashMap<String, String>();
						map.put("HypertensionVisiting_VisitingType", "VisitingTypes"); //随访方式
						map.put("Type2Diabetes_Symptom", "Symptoms");//症状
						map.put("Type2Diabetes_Arteriopalmus", "Arteriopalmus");//足背动脉搏动
						map.put("HypertensionVisiting_PsychplogicalRecover", "PsychplogicalRecovers");//心理调整、遵医行为
						map.put("PsychosisFollowUp_sDrugCompliance", "DrugCompliances");//药物服从性
						map.put("HypertensionVisiting_DrugReaction", "DrugReactions");//药物不良反应
						map.put("Type2Diabetes_Hypoglycemia", "Hypoglycemia");//低血糖反应
						map.put("HypertensionVisiting_VisitingClassify", "VisitingClassifys");//此次随访分类
						JSONObject jsonObj = CommonUtil.getAllDictionary(map);
						if(personInfo!=null){
							jsonObj.put("sName", personInfo.getsPersonName());  //页面回显姓名
							jsonObj.put("sNo", personInfo.getsNo());	        //页面回显档案号
						}
						jsonObj.put("dVisitingDate", DateTools.getFormatStringByDF_YYYY_MM_DD(new Date()));//页面回显随访日期
						jsonObj.put("dNextVisitingDate", DateTools.getFormatStringByDF_YYYY_MM_DD(DateTools.getNextMonthByDate(new Date(),3)));//下次随访日期
						jsonObj.put("sNextVisitingPlace", info.getsOrganizationName());//随访单位
						jsonObj.put("DoctorList", info.getJsonArrayDoctors());//回显随访医生列表
						jsonObj.put("sVisitingDoctor", info.getsUserName());//随访医生

						JSONArray jsonObj2 =null;
						if(jsonstr!=null){
							jsonstr = jsonstr.replace("\\n", "");
							jsonObj2 = new JSONArray(jsonstr);
						}
						// 初始化dAddTime
						String json = jsonObj.toString();
						webView.loadUrl("javascript:showHtml('" + json + "','"+jsonObj2+"','"+ishuixian+"')");
//						webView.loadUrl("javascript:showHtml('" + json + "','" + jsonObj2 + "')");
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			});
		}
		//保存操作
		@JavascriptInterface
		public void save(String uploadType,String sVisitingClassifyName,String sHypoglycemiaName,String sDrugReactionName,String sDrugComplianceName,String sCompianceName,String sPsychplogicalRecoveryName,String sArteriopalmusName,String sSymptomName,String sVisitingTypeName,String txtdHeight,String sName,String sNo,String dVisitingDate,String sVisitingTypeCode,String sSymptomCode,String sSymptomOther,String iSystolicPressure,String iDiastolicPressure,
				String dWeight1,String dWeight2,String dBodyMassIndex1,String dBodyMassIndex2,String sArteriopalmusCode,String sOther,String nDaySmoke1,String nDaySmoke2,String nDayDrink1,String nDayDrink2,
				String nSport_EveryWeek1,String nSport_EveryMinute1,String nSport_EveryWeek2,String nSport_EveryMinute2,String sStapleFood1,String sStapleFood2,String sPsychplogicalRecoveryCode,
				String sCompianceCode,String dFastingBloodGlucose,String dGlycosylatedHemoglobin,String dCheckDate,String sOtherCheck,String sDrugComplianceCode,String sDrugReactionCode,String sDrugReactionOther,String sHypoglycemiaCode,String sVisitingClassifyCode,String sTransferTreatment,
				String sTransferTreatmentDept,String dNextVisitingDate,String sNextVisitingPlace,String sVisitingDoctor,String iWeatherHealthEducation,String sWeatherHealthEducationContent,
				String BaoJianZhidaoContent,String BaoJianZhidaoContentCode,String sDrugName1,String iDrug_EveryDay1,String sDrug_EveryTime1,String sDrugName2,String iDrug_EveryDay2,String sDrug_EveryTime2,
				String sDrugName3,String iDrug_EveryDay3,String sDrug_EveryTime3,String sInsulinType,String sInsulinUsage,String sDrugQtdw1,String sDrugQtdw2,String sDrugQtdw3,String sDrug_qitadw1,String sDrug_qitadw2,String sDrug_qitadw3){
			try {

				String gType2DiabetsKey = CommonUtil.getUUID();
				final JSONArray jsonArrayData = new JSONArray();
				JSONObject jsonData = new JSONObject();
				JSONObject jsonVistingInfo = new JSONObject();

				jsonVistingInfo.put("xueya", xueya);
				jsonVistingInfo.put("xuetang", xuetang);
				jsonVistingInfo.put("xuehongdanbai", xuehongdanbai);


				jsonVistingInfo.put("gKey", gType2DiabetsKey);
				if(personInfo!=null){
					jsonVistingInfo.put("sPersonID", personInfo.getsPersonID());
					jsonVistingInfo.put("sNo", personInfo.getsNo());
				}else{
					jsonVistingInfo.put("sPersonID", sPersonID1);
					jsonVistingInfo.put("sNo", sNo1);
				}

				jsonVistingInfo.put("sName", sName);
				jsonVistingInfo.put("txtdHeight", txtdHeight);//?
				jsonVistingInfo.put("dVisitingYear", dVisitingDate.substring(0,4));
				jsonVistingInfo.put("dVisitingDate", dVisitingDate);
				jsonVistingInfo.put("sVisitingTypeName", sVisitingTypeName);
				jsonVistingInfo.put("sVisitingTypeCode", sVisitingTypeCode);
				jsonVistingInfo.put("sSymptomName", sSymptomName);
				jsonVistingInfo.put("sSymptomCode", sSymptomCode);
				jsonVistingInfo.put("sSymptomOther", sSymptomOther);
				jsonVistingInfo.put("iSystolicPressure", iSystolicPressure);
				jsonVistingInfo.put("iDiastolicPressure", iDiastolicPressure);
				jsonVistingInfo.put("dWeight1", dWeight1);
				jsonVistingInfo.put("dWeight2", dWeight2);
				jsonVistingInfo.put("dBodyMassIndex1", dBodyMassIndex1);
				jsonVistingInfo.put("dBodyMassIndex2", dBodyMassIndex2);
				jsonVistingInfo.put("sArteriopalmusName", sArteriopalmusName);
				jsonVistingInfo.put("sArteriopalmusCode", sArteriopalmusCode);
				jsonVistingInfo.put("sOther", sOther);
				jsonVistingInfo.put("nDaySmoke1", nDaySmoke1);
				jsonVistingInfo.put("nDaySmoke2", nDaySmoke2);
				jsonVistingInfo.put("nDayDrink1", nDayDrink1);
				jsonVistingInfo.put("nDayDrink2", nDayDrink2);
				jsonVistingInfo.put("nSport_EveryWeek1", nSport_EveryWeek1);
				jsonVistingInfo.put("nSport_EveryWeek2", nSport_EveryWeek2);
				jsonVistingInfo.put("nSport_EveryMinute1", nSport_EveryMinute1);
				jsonVistingInfo.put("nSport_EveryMinute2", nSport_EveryMinute2);
				jsonVistingInfo.put("sStapleFood1", sStapleFood1);
				jsonVistingInfo.put("sStapleFood2", sStapleFood2);
				jsonVistingInfo.put("sPsychplogicalRecoveryName", sPsychplogicalRecoveryName);
				jsonVistingInfo.put("sPsychplogicalRecoveryCode", sPsychplogicalRecoveryCode);
				jsonVistingInfo.put("sCompianceName", sCompianceName);
				jsonVistingInfo.put("sCompianceCode", sCompianceCode);
				jsonVistingInfo.put("dFastingBloodGlucose", dFastingBloodGlucose);
				jsonVistingInfo.put("dGlycosylatedHemoglobin", dGlycosylatedHemoglobin);
				jsonVistingInfo.put("dCheckDate", dCheckDate);
				jsonVistingInfo.put("sOtherCheck", sOtherCheck);
				jsonVistingInfo.put("sDrugComplianceName", sDrugComplianceName);
				jsonVistingInfo.put("sDrugComplianceCode", sDrugComplianceCode);
				jsonVistingInfo.put("sDrugReactionName", sDrugReactionName);
				jsonVistingInfo.put("sDrugReactionCode", sDrugReactionCode);
				jsonVistingInfo.put("sDrugReactionOther", sDrugReactionOther);
				jsonVistingInfo.put("sHypoglycemiaName", sHypoglycemiaName);
				jsonVistingInfo.put("sHypoglycemiaCode", sHypoglycemiaCode);
				jsonVistingInfo.put("sVisitingClassifyName", sVisitingClassifyName);
				jsonVistingInfo.put("sVisitingClassifyCode", sVisitingClassifyCode);
				jsonVistingInfo.put("sInsulinType", sInsulinType);
				jsonVistingInfo.put("sInsulinUsage", sInsulinUsage);
				jsonVistingInfo.put("sTransferTreatment", sTransferTreatment);
				jsonVistingInfo.put("sTransferTreatmentDept", sTransferTreatmentDept);
				jsonVistingInfo.put("dNextVisitingDate", dNextVisitingDate);
				jsonVistingInfo.put("sVisitingDoctor", sVisitingDoctor);
				jsonVistingInfo.put("sAddUser", info.getsLoginName());
				jsonVistingInfo.put("dAddTime", DateTools.getFormatStringByDF_YYYY_MM_DD_HH_MM_SS(new Date()));
				jsonVistingInfo.put("sUpdateUser", "");
				jsonVistingInfo.put("dUpdateTime", "");
				jsonVistingInfo.put("sDeleteUser", "");
				jsonVistingInfo.put("dDeleteTime", "");
				jsonVistingInfo.put("sInputDeptName", info.getsOrganizationName());
				jsonVistingInfo.put("sInputDeptCode", info.getsOrganizationKey());
				jsonVistingInfo.put("iState", 1);
				jsonVistingInfo.put("sAreaCode", personInfo.getsAreaCode());
				jsonVistingInfo.put("sAreaName", personInfo.getsPersonName());
				jsonVistingInfo.put("iWeatherHealthEducation", iWeatherHealthEducation);
				jsonVistingInfo.put("sWeatherHealthEducationContent", sWeatherHealthEducationContent);
				jsonVistingInfo.put("BaoJianZhidaoContent", BaoJianZhidaoContent);
				jsonVistingInfo.put("BaoJianZhidaoContentCode", BaoJianZhidaoContentCode);
				jsonVistingInfo.put("sVisitingDoctorCode", "");
				jsonVistingInfo.put("sVisitingPlaceCode", "");
				jsonVistingInfo.put("sNextVisitingPlace", sNextVisitingPlace);
				jsonArrayData.put(jsonVistingInfo);
				JSONArray jsonArray = new JSONArray();
				if(StringTools.isNotEmpty(sDrugName1)){
					JSONObject jsonObj = new JSONObject();
					jsonObj.put("gKey", CommonUtil.getUUID());
					jsonObj.put("gType2DiabetsKey", gType2DiabetsKey);
					if(personInfo!=null){
						jsonObj.put("sPersonID", personInfo.getsPersonID());
					}else{
						jsonObj.put("sPersonID", sPersonID1);
					}
					jsonObj.put("sDrugName", sDrugName1);
					jsonObj.put("iDrug_EveryDay", iDrug_EveryDay1);
					jsonObj.put("sDrug_EveryTime", sDrug_EveryTime1);
					jsonObj.put("sAddUser", info.getsLoginName());
					jsonObj.put("dAddTime", DateTools.getFormatStringByDF_YYYY_MM_DD_HH_MM_SS(new Date()));
					jsonObj.put("sUpdateUser", "");
					jsonObj.put("dUpdateTime", "");
					jsonObj.put("sDeleteUser", "");
					jsonObj.put("dDeleteTime", "");
					jsonObj.put("sDrugQtdw", sDrugQtdw1);
					jsonObj.put("sDrug_qitadw", sDrug_qitadw1);
					jsonObj.put("sInputDeptName", info.getsOrganizationName());
					jsonObj.put("sInputDeptCode", info.getsOrganizationKey());
					jsonObj.put("iState", 1);
					jsonObj.put("sort","1");
					jsonArray.put(jsonObj);
				}
				if(StringTools.isNotEmpty(sDrugName2)){
					JSONObject jsonObj = new JSONObject();
					jsonObj.put("gKey", CommonUtil.getUUID());
					jsonObj.put("gType2DiabetsKey", gType2DiabetsKey);
					if(personInfo!=null){
						jsonObj.put("sPersonID", personInfo.getsPersonID());
					}else{
						jsonObj.put("sPersonID", sPersonID1);
					}
					jsonObj.put("sDrugName", sDrugName2);
					jsonObj.put("iDrug_EveryDay", iDrug_EveryDay2);
					jsonObj.put("sDrug_EveryTime", sDrug_EveryTime2);
					jsonObj.put("sAddUser", info.getsLoginName());
					jsonObj.put("dAddTime", DateTools.getFormatStringByDF_YYYY_MM_DD_HH_MM_SS(new Date()));
					jsonObj.put("sUpdateUser", "");
					jsonObj.put("dUpdateTime", "");
					jsonObj.put("sDeleteUser", "");
					jsonObj.put("dDeleteTime", "");
					jsonObj.put("sDrugQtdw", sDrugQtdw2);
					jsonObj.put("sDrug_qitadw", sDrug_qitadw2);
					jsonObj.put("sInputDeptName", info.getsOrganizationName());
					jsonObj.put("sInputDeptCode", info.getsOrganizationKey());
					jsonObj.put("iState",1);
					jsonObj.put("sort","2");
					jsonArray.put(jsonObj);
				}
				if(StringTools.isNotEmpty(sDrugName3)){
					JSONObject jsonObj = new JSONObject();
					jsonObj.put("gKey", CommonUtil.getUUID());
					jsonObj.put("gType2DiabetsKey", gType2DiabetsKey);
					if(personInfo!=null){
						jsonObj.put("sPersonID", personInfo.getsPersonID());
					}else{
						jsonObj.put("sPersonID", sPersonID1);
					}
					jsonObj.put("sDrugName", sDrugName3);
					jsonObj.put("iDrug_EveryDay", iDrug_EveryDay3);
					jsonObj.put("sDrug_EveryTime", sDrug_EveryTime3);
					jsonObj.put("sAddUser", info.getsLoginName());
					jsonObj.put("dAddTime", DateTools.getFormatStringByDF_YYYY_MM_DD_HH_MM_SS(new Date()));
					jsonObj.put("sUpdateUser", "");
					jsonObj.put("dUpdateTime", "");
					jsonObj.put("sDeleteUser", "");
					jsonObj.put("dDeleteTime", "");
					jsonObj.put("sDrugQtdw", sDrugQtdw3);
					jsonObj.put("sDrug_qitadw", sDrug_qitadw3);
					jsonObj.put("sInputDeptName", info.getsOrganizationName());
					jsonObj.put("sInputDeptCode", info.getsOrganizationKey());
					jsonObj.put("iState", 1);
					jsonObj.put("sort","3");
					jsonArray.put(jsonObj);
				}
				jsonData.put("sMedicalList", jsonArray);
				jsonArrayData.put(jsonData);
				Log.i("benny", jsonArrayData.toString());
				if("2".equals(uploadType)){
					DiabetesMellitusFollowUpActivity.this.runOnUiThread(new Runnable() {
						@Override
						public void run() {
							try {
								boolean issuccess=false;
								if(updateIndex>=0&&personInfo==null){

									 issuccess=new FileService(act).updateFromRom(updateIndex,sPersonID1, sNo1, sname1, sCardNo1, "糖尿病患者随访", jsonArrayData.toString(), "append.txt");
								}else{
								 issuccess=new FileService(act).saveToRom(personInfo.getsPersonID(),personInfo.getsNo(),personInfo.getsPersonName(),personInfo.getsCardNo(), "糖尿病患者随访", jsonArrayData.toString(), "append.txt");
								}if(issuccess){
									MessageTools.showDialogOk(ctx, "保存成功！本次随访数据保存在本机，请到“离线设置”-“上传随访信息”中上传或者修改数据！");
								}else{
									 Toast.makeText(DiabetesMellitusFollowUpActivity.this, "保存失败！", Toast.LENGTH_SHORT).show();
								 }
							} catch (Exception e) {
								 Toast.makeText(DiabetesMellitusFollowUpActivity.this, "保存失败！", Toast.LENGTH_SHORT).show();
								e.printStackTrace();
							}
						}});
				}
				else if(BphsConstants.isNetAvailable&&"1".equals(uploadType)){
				DiabetesMellitusFollowUpActivity.this.runOnUiThread(new Runnable() {
					@Override
					public void run() {
						//创建了对话框的构造器
						Builder builder = new Builder(DiabetesMellitusFollowUpActivity.this);
						builder.setTitle("温馨提示");
						builder.setMessage("确定将本次随访数据提交至服务器吗？注意：提交后本条数据无法在平板上再次修改！");
						builder.setPositiveButton("确定", new OnClickListener() {

							public void onClick(DialogInterface dialog, int which) {
								try {
								String serviceURL = BphsURL.getCommonPath("AddType2Diabetes_URL");
								String methodName = BphsURL.getCommonPath("AddType2Diabetes_METHOD");
//								String methodName = "AddType2DiabetesVisiting";    
//								String serviceURL = "http://60.171.146.122:9098/WebService/Andrews/Type2DiabetesWebService.asmx";
								String result =	WebServiceUtils.requestByParams(methodName, jsonArrayData.toString(), serviceURL);
								if(StringUtils.isNotBlank(result)){
									JSONObject json = new JSONObject(result);
									 String sResult = json.getString("sSuccess");
									 if(sResult.equals("1")){
										 Toast.makeText(DiabetesMellitusFollowUpActivity.this, "保存完成！", Toast.LENGTH_SHORT).show();
									 }else{
										 Toast.makeText(DiabetesMellitusFollowUpActivity.this, "保存失败！", Toast.LENGTH_SHORT).show();
									 }
								}else{
									Toast.makeText(DiabetesMellitusFollowUpActivity.this, "远程服务器故障！", Toast.LENGTH_SHORT).show();
								}
							} catch (Exception e) {
								e.printStackTrace();
							}
							}
						});
						builder.setNegativeButton("取消", new OnClickListener() {

							public void onClick(DialogInterface dialog, int which) {
								 Toast.makeText(DiabetesMellitusFollowUpActivity.this, "保存失败！", Toast.LENGTH_SHORT).show();
							}
						});
						AlertDialog dialog =builder.create();
						dialog.setCancelable(false);
						dialog.setCanceledOnTouchOutside(false);
						dialog.show();
						
					}
				});}else{
					 Toast.makeText(DiabetesMellitusFollowUpActivity.this, "离线状态只能保存随访信息！", Toast.LENGTH_LONG).show();
				}
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}
		//调用蓝牙接口返回xml数据
		@JavascriptInterface
		public void getXML(String type){
			switch (BphsConstants.deviceBranchType) {
			case 0:
			Intent intent = new Intent();
			// 通讯接口
			intent.setComponent(new ComponentName("com.example.uray.bluetooth.comm.app", "com.example.uray.bluetooth.comm.app.CommActivity"));
			// 参数配置接口
			//intent.setComponent(new ComponentName("com.example.uray.bluetooth.comm.app", "com.example.uray.bluetooth.comm.app.ConfigActivity"));
			intent.setAction(Intent.ACTION_VIEW);   
			if(type.equals("1")){ 
				startActivityForResult(intent, 1);  //获取血压值
			}else if(type.equals("2")){
				startActivityForResult(intent, 2);  //获取血糖值
			}else{
				startActivityForResult(intent, 3);  //获取血红蛋白值
			}
			break;
			case 1:	
				if ("1".equals(type)) {
					Intent iNibp = new Intent(DiabetesMellitusFollowUpActivity.this,
							NibpExample.class);
					startActivityForResult(iNibp, 4); // 获取血压值
//					startActivity(iNibp);
				} else if ("2".equals(type)) {
					Intent iGlu = new Intent(DiabetesMellitusFollowUpActivity.this, GluExample.class);
					startActivityForResult(iGlu, 5); // 获取血糖值
					
				}else{
					MessageTools.showDialogOk(ctx, "当前功能还未开通，请手动输入！");  //获取血红蛋白值
				}
				break;
			default:
				break;
			}
		}
	}
	
	// 解析蓝牙接口返回的XML格式的字符串
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
          super.onActivityResult(requestCode, resultCode, data); 
        if(requestCode == 1 && resultCode == RESULT_OK){
        	//获取血压值
        	String sb = data.getStringExtra("return");
//        	StringBuffer sb = new StringBuffer(); 
//        	try {
//        	InputStream in = getResources().getAssets().open("c.xml");
//            byte[]  b = new byte[4096]; 
//            int n;
//            while ((n = in.read(b))!= -1){ 
//                sb.append(new String(b,0,n)); 
//            }
//            } catch (IOException e) {
//				e.printStackTrace();
//			}
        	String jsonStr =  XmlUtil.parseXml(sb);
//       	MessageTools.showDialogOk(ctx, "返回结果", sb);
//        	Toast.makeText(ctx, a, 1).show();
        	xueya="1";
        	webView.loadUrl("javascript:showXML('" + jsonStr + "')");
        } 
        if(requestCode == 2 && resultCode == RESULT_OK){
        	//获取血糖值
        	String sb = data.getStringExtra("return");
//        	StringBuffer sb = new StringBuffer(); 
//        	try {
//        	InputStream in = getResources().getAssets().open("c.xml");
//            byte[]  b = new byte[4096]; 
//            int n;
//            while ((n = in.read(b))!= -1){ 
//                sb.append(new String(b,0,n)); 
//            }
//            } catch (IOException e) {
//				e.printStackTrace();
//			}
        	String jsonStr =  XmlUtil.parseXml(sb);
//       	MessageTools.showDialogOk(ctx, "返回结果", sb);
//        	Toast.makeText(ctx, a, 1).show();
        	xuetang="1";
        	webView.loadUrl("javascript:showXML2('" + jsonStr + "')");
        } 
        if(requestCode == 3 && resultCode == RESULT_OK){
        	//获取血红蛋白值
        	String sb = data.getStringExtra("return");
//        	StringBuffer sb = new StringBuffer(); 
//        	try {
//        	InputStream in = getResources().getAssets().open("c.xml");
//            byte[]  b = new byte[4096]; 
//            int n;
//            while ((n = in.read(b))!= -1){ 
//                sb.append(new String(b,0,n)); 
//            }
//            } catch (IOException e) {
//				e.printStackTrace();
//			}
        	String jsonStr =  XmlUtil.parseXml(sb);
//       	MessageTools.showDialogOk(ctx, "返回结果", sb);
//        	Toast.makeText(ctx, a, 1).show();
        	xuehongdanbai="1";
        	webView.loadUrl("javascript:showXML3('" + jsonStr + "')");
        }
        if(requestCode == 4&&data!=null){
			// 获取血压值
			String jsonstr = data.getStringExtra("jsonstr");
			xueya="1";
			webView.loadUrl("javascript:showXML('" + jsonstr + "')");
			
		}
        if(requestCode == 5&&data!=null){
        	//获取血糖值
			String jsonstr = data.getStringExtra("jsonstr");
			xuetang="1";
			webView.loadUrl("javascript:showXML2('" + jsonstr + "')");
			
		}
    }
}
